package com.newcoder.controller;

import com.newcoder.entity.DiscussPost;
import com.newcoder.service.impl.DiscussPostServiceImpl;
import com.newcoder.util.ResponseWrapper;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yjh
 * @since 2024-12-04 10:03:26
 */
@RestController
@RequestMapping("/discuss-post")
public class DiscussPostController {

    @Autowired
    DiscussPostServiceImpl discussPostService;

    @ApiOperation("新增文章")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "discussPost",value = "文章表单"),
    })
    @PostMapping("/insertDiscussPost")
    public ResponseWrapper insertDiscussPost(@RequestBody DiscussPost discussPost){
        ResponseWrapper wrapper = discussPostService.insertDiscussPost(discussPost);
        return wrapper;
    }

    @ApiOperation("删除文章")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "文章id"),
    })
    @GetMapping("/deleteDiscussPostById")
    public ResponseWrapper deleteDiscussPostById(@RequestParam(name = "id")Integer id){
        ResponseWrapper wrapper = discussPostService.deleteDiscussPostById(id);
        return wrapper;
    }

    @ApiOperation("修改文章")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "discussPost",value = "文章表单"),
    })
    @PostMapping("/updateDiscussPost")
    public ResponseWrapper updateDiscussPost(@RequestBody DiscussPost discussPost){
        ResponseWrapper wrapper = discussPostService.updateDiscussPost(discussPost);
        return wrapper;
    }

    @ApiOperation("查找文章详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "文章id"),
    })
    @GetMapping("/selectDiscussPostById")
    public ResponseWrapper selectDiscussPostById(@RequestParam(name = "id")Integer id){
        ResponseWrapper wrapper = discussPostService.selectDiscussPostById(id);
        return wrapper;
    }

    @ApiOperation("查询某一页文章数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "status", defaultValue = "null"),
            @ApiImplicitParam(name = "type", defaultValue = "null"),
            @ApiImplicitParam(name = "currentPage",value = "当前页码数",defaultValue = "1"),
            @ApiImplicitParam(name = "pageSize",value = "每页展示的数据条数",defaultValue = "10"),
    })
    @GetMapping("/selectDiscussPostsPage")
    public ResponseWrapper selectDiscussPostsPage(@RequestParam(name = "status",defaultValue = "123")Integer status,
                                          @RequestParam(name = "type",defaultValue = "123")Integer type,
                                          @RequestParam(name = "currentPage",defaultValue = "1")Integer currentPage,
                                          @RequestParam(name = "pageSize",defaultValue = "10")Integer pageSize){
        ResponseWrapper wrapper = discussPostService.selectDiscussPostsPage(status, type, currentPage, pageSize);
        return wrapper;
    }

    @ApiOperation("查看谈论页详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "discussPostId",value = "文章id"),
    })
    @GetMapping("/getDiscussPost")
    public ResponseWrapper getDiscussPost(Integer discussPostId){
        ResponseWrapper wrapper = discussPostService.getDiscussPost(discussPostId);
        return wrapper;
    }

    @ApiOperation("置顶")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "评论id"),
    })
    @GetMapping("/setTop")
    public ResponseWrapper setTop(Integer id){
        ResponseWrapper wrapper = discussPostService.setTop(id);
        return wrapper;
    }

    @ApiOperation("设置为精选")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "评论id"),
    })
    @GetMapping("/setWonderful")
    public ResponseWrapper setWonderful(Integer id){
        ResponseWrapper wrapper = discussPostService.setWonderful(id);
        return wrapper;
    }
}
